﻿using GpCommon;
using GpCommon.Helpers;
using GPSpeedView.GPHelpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace GPSpeedView.Views
{
    /// <summary>
    /// GpInfoView.xaml 的交互逻辑
    /// </summary>
    public partial class GpInfoView : Window
    {
        public GpInfoView()
        {
            InitializeComponent();
            InitData();
        }

        private void InitData()
        {
            try
            {
                var dayList = GpLocalDataHelper.GetLocalHistoryDayInfoByCode(DateTime.Now.Year, CommonData.TargetCode);
                if(dayList != null && dayList.Count > 0)
                {
                    dayList = dayList.OrderBy(x => x.Time).ToList();

                    dayInfoStartBlock.Text = dayList[0].Time.ToShortDateString();
                    dayInfoEndBlock.Text = dayList[dayList.Count - 1].Time.ToShortDateString();
                }
                var ms5List = GpLocalDataHelper.GetDay5MSEntitiesByCode(DateTime.Now.Year, CommonData.TargetCode);
                if (ms5List != null &&ms5List.Count > 0)
                {
                    ms5List = ms5List.OrderBy(x => x.CurTime).ToList();

                    ms5InfoStartBlock.Text = ms5List[0].CurTime.ToShortDateString();
                    ms5InfoEndBlock.Text = ms5List[ms5List.Count - 1].CurTime.ToShortDateString();
                }
                var ms1List = GpLocalDataHelper.GetDay1MSEntitiesByCode(DateTime.Now.Year, CommonData.TargetCode);
                if (ms1List != null && ms1List.Count > 0)
                {
                    ms1List = ms1List.OrderBy(x => x.CurTime).ToList();

                    ms1InfoStartBlock.Text = ms1List[0].CurTime.ToShortDateString();
                    ms1InfoEndBlock.Text = ms1List[ms1List.Count - 1].CurTime.ToShortDateString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
